/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\line_segment.h"

BOOST_AUTO_TEST_SUITE( line_segment2d )


BOOST_AUTO_TEST_CASE( line_segment2d__default_constructor )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.extent() == 0 );

	sgl::line_segment<2> b(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4);

	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.direction()[0] == 3 );
	BOOST_CHECK( b.extent() == 4 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__copy_constructor )
{
	sgl::line_segment<2> a(
		sgl::line_segment<2>(
			sgl::point<2>(1, 2),
			sgl::direction<2>(3),
			4));

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 3 );
	BOOST_CHECK( a.extent() == 4 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__copy_assignment )
{
	sgl::line_segment<2> a;
	a = sgl::line_segment<2>(
			sgl::point<2>(1, 2),
			sgl::direction<2>(3),
			4);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 3 );
	BOOST_CHECK( a.extent() == 4 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__swap )
{
	sgl::line_segment<2> a(sgl::line_segment<2>(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4));
	sgl::line_segment<2> b;

	a.swap(b);

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.extent() == 0 );
	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.direction()[0] == 3 );
	BOOST_CHECK( b.extent() == 4 );

	b.swap(a);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 3 );
	BOOST_CHECK( a.extent() == 4 );
	BOOST_CHECK( b.origin()[0] == 0 );
	BOOST_CHECK( b.origin()[1] == 0 );
	BOOST_CHECK( b.direction()[0] == 0 );
	BOOST_CHECK( b.extent() == 0 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__origin )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );

	a.origin()[0] = 1;
	a.origin()[1] = 1;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__direction )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.direction()[0] == 0 );

	a.direction()[0] = 1;

	BOOST_CHECK( a.direction()[0] == 1 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__extent )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.extent() == 0 );

	a.extent() = 1;

	BOOST_CHECK( a.extent() == 1 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__geometric_type )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::line_segment );
}

BOOST_AUTO_TEST_CASE( line_segment2d__dimensions )
{
	sgl::line_segment<2> a;

	BOOST_CHECK( a.dimensions() == 2 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__operator_minus )
{
	sgl::line_segment<2> a;
	sgl::line_segment<2> b = -a;

	BOOST_CHECK( b.origin()[0] == 0 );
	BOOST_CHECK( b.origin()[1] == 0 );
	BOOST_CHECK( b.direction()[0] == M_PI );
	BOOST_CHECK( b.extent() == 0 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__operator_equality )
{
	sgl::line_segment<2> a;
	sgl::line_segment<2> b;

	BOOST_CHECK( a == b );

	sgl::line_segment<2> c(sgl::point<2>(1, 2), sgl::direction<2>(3), 4);
	sgl::line_segment<2> d(sgl::point<2>(1, 2), sgl::direction<2>(3), 4);

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( line_segment2d__operator_inequality )
{
	sgl::line_segment<2> a;
	sgl::line_segment<2> b(sgl::point<2>(1, 2), sgl::direction<2>(3), 4);

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( line_segment2d__addition )
{
	sgl::line_segment<2> a;
	a += sgl::vector<2>(1, 2);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.extent() == 0 );

	sgl::line_segment<2> b;
	sgl::vector<2> c(1, 2);
	sgl::line_segment<2> d = b+c;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.direction()[0] == 0 );
	BOOST_CHECK( d.extent() == 0 );

	sgl::line_segment<2> e = c+b;

	BOOST_CHECK( e.origin()[0] == 1 );
	BOOST_CHECK( e.origin()[1] == 2 );
	BOOST_CHECK( e.direction()[0] == 0 );
	BOOST_CHECK( e.extent() == 0 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__subtraction )
{
	sgl::line_segment<2> a;
	a -= sgl::vector<2>(1, 2);

	BOOST_CHECK( a.origin()[0] == -1 );
	BOOST_CHECK( a.origin()[1] == -2 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.extent() == 0 );

	sgl::line_segment<2> b;
	sgl::vector<2> c(1, 2);
	sgl::line_segment<2> d = b-c;

	BOOST_CHECK( d.origin()[0] == -1 );
	BOOST_CHECK( d.origin()[1] == -2 );
	BOOST_CHECK( d.direction()[0] == 0 );
	BOOST_CHECK( d.extent() == 0 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__multiplication )
{
	sgl::line_segment<2> a(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4);
	a *= 2;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 3 );
	BOOST_CHECK( a.extent() == 8 );

	sgl::line_segment<2> b(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4);
	sgl::line_segment<2> d = b*3;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.direction()[0] == 3 );
	BOOST_CHECK( d.extent() == 12 );

	sgl::line_segment<2> e = 3*b;

	BOOST_CHECK( e.origin()[0] == 1 );
	BOOST_CHECK( e.origin()[1] == 2 );
	BOOST_CHECK( e.direction()[0] == 3 );
	BOOST_CHECK( e.extent() == 12 );
}

BOOST_AUTO_TEST_CASE( line_segment2d__division )
{
	sgl::line_segment<2> a(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4);
	a /= 2;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.direction()[0] == 3 );
	BOOST_CHECK( a.extent() == 2 );

	sgl::line_segment<2> b(
		sgl::point<2>(1, 2),
		sgl::direction<2>(3),
		4);
	sgl::line_segment<2> d = b/2;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.direction()[0] == 3 );
	BOOST_CHECK( d.extent() == 2 );
}

BOOST_AUTO_TEST_SUITE_END()

